package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    TbClueMapper tbClueMapper;
    @Autowired
    TbClueTrackRecordMapper tbClueTrackRecordMapper;
    /**
     * 查询线索跟进记录列表
     * @return
     */
    public int saveClueFollow(ClueTrackRecordVo clueTrackRecord) {
        TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();
        //拷贝(clueTrackRecord,tbClueTrackRecord)（被拷贝的对象,拷贝到的对象）
        BeanUtils.copyProperties(clueTrackRecord,tbClueTrackRecord);
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecord.setCreateTime(DateUtils.getNowDate());
        tbClueTrackRecord.setType("0");
        tbClueMapper.updateClueTrackRecordVo(clueTrackRecord);
        //修改状态
        tbClueMapper.resetNextTimeAndStatus(clueTrackRecord.getClueId(), "2");
        tbClueTrackRecordMapper.insertTbClueTrackRecord(tbClueTrackRecord);
        return 1;
    }

    @Override
    public List<TbClueTrackRecord> selectTbClueTrackRecords(Long clueId) {
        return tbClueTrackRecordMapper.selectTbClueTrackRecordById(clueId);
    }
}
